

import java.io.IOException;
import java.util.List;

import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sessionbeans.FriendshipBeanRemote;

import entities.PendingFriendship;

/**
 * Servlet implementation class PendingFriendshipServlet
 */
public class PendingFriendshipServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PendingFriendshipServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		InitialContext context;
		List<PendingFriendship> pendingRequests;
		FriendshipBeanRemote friendshipBean;
		String user = (String) request.getSession().getAttribute("userId");
		
		try {
			context = new InitialContext();
			Object ref = context.lookup("FriendshipBeanRemote");
			friendshipBean = (FriendshipBeanRemote)PortableRemoteObject.narrow(ref, FriendshipBeanRemote.class);
			pendingRequests = friendshipBean.getPendingFriendships(user);
			request.getSession().setAttribute("pendingfriendship", pendingRequests);
			response.sendRedirect("PendingFriendshipPage.jsp");
		} catch (Exception e) {
			System.out.println("Naming exception");
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
